package written_test;

import java.util.*;

/**
 * @author zhx
 * @since 2020-09-13
 */
public class NetEase {

    public static void main1(String[] args) {
        //64
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] s = str.split(" ");
        int distance = 0;
        for (int i = 0; i < s.length; i++) {
            if (Objects.equals("0", s[i])) {
                int j = i; // left
                int k = i; // right
                for (; j > 0; j--) {
                    if (Objects.equals("1", s[j])) {
                        break;
                    }
                }
                for (; k < s.length; k++) {
                    if (Objects.equals("1", s[k])) {
                        break;
                    }
                }
                int tmp = Math.min(i - j, k - i);
                distance = Math.max(distance, tmp);
            }
        }
        System.out.println(distance);
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
//        List<String> list = new ArrayList<>();

        int sum = 0;
//        int pos = 0;
//        for (int i = 0; i < str.length() - 3; i++) {
//            if (str.substring(i, i + 3).equals("100")) {
//                list.add(str.substring(pos, i + 3));
//                pos = i + 3;
//            }
//        }
//        list.add(str.substring(pos));
//        for (String s : list) {
//            sum += dp(s);
//        }
//        list.forEach(System.out::println);
        String[] split = str.split("100");
//        Arrays.stream(split).forEach(System.out::println);
        for (String s : split) {
            sum += dp(s);
        }
        System.out.println(sum);
    }

    public static int dp(String str) {
        if (str.length() == 0) {
            return 1;
        }
        if (str.length() == 1) {
            return 1+1;
        }
        int[] dp = new int[str.length()];
        dp[0] = 1;
        dp[1] = 2;
//        dp[2] = 3;
        if (str.length() < 3) {
            return dp[str.length() - 1];
        }
        for (int i = 2; i < str.length(); i++) {
            dp[i] = dp[i - 1] + dp[i - 2];//+dp[i-3];
        }
        return dp[str.length() - 1]+1;
    }


    public static void main(String[] args) {
        Map<Integer,List<Integer[]>> listMap = new HashMap<>(); // integer[]:destination,weight
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int start = in.nextInt();
        int m = in.nextInt();
        int sum = 0;
        for (int i = 0; i < m; i++) {
            int key = in.nextInt();
            List<Integer[]> list;
            if (listMap.containsKey(key)){
                list = listMap.get(key);
            } else {
                list = new ArrayList<>();
            }
            list.add(new Integer[]{in.nextInt(),in.nextInt()});
            listMap.put(key, list);
        }
        List<Integer[]> list = listMap.get(start);
        for (int i = 0; i < list.size(); i++) {

        }
    }

    public static int dfs(Map<Integer,List<Integer[]>> listMap,List<Integer[]> list,int sum){
        return 0;
    }


}
